<?php
class UploadFile{
    protected $uploadName;
    protected $file=null;
    function __construct($uploadName){
        $this->uploadName=$uploadName;
        if(array_key_exists($uploadName,$_FILES)){
            $this->file=$_FILES[$uploadName];
        }
    }
    
    public function isExists(){
        return ($this->file!=null);
    }
    
    public function getClientName(){
        return $this->file["name"];
    }
    
    public function getExt(){
        $fn=$this->getClientName();
        $pi=pathinfo($fn);
        return $pi["extension"];
    }
    
    
    public function getSize(){
        return $this->file["size"];
    }
    
    public function isUploaded(){
        return ($this->file["error"]==0);
    }
    public function getTmpName(){
        return $this->file["tmp_name"];
    }
    
    
    /**
     * 保存文件
     * @param string $path 保存路径
     * @return bool 成功返回true,失败返回false
     */
    public function saveAs($path){
        if($this->isExists() && $this->isUploaded()){
            return move_uploaded_file($this->file["tmp_name"],$path);
        }
        return false;
    }
}